package com.zoro.dyformservice.business.role.service;

import com.zoro.dyformservice.business.role.dto.FindAllRoleInfoDto;
import com.zoro.dyformservice.business.role.entity.RoleInfo;
import com.zoro.dyformservice.business.role.repository.RoleInfoRepository;
import com.zoro.dyformservice.utils.jpa.WhereMakerUtils;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleInfoService {
    private final RoleInfoRepository roleInfoRepository;

    public RoleInfoService(RoleInfoRepository roleInfoRepository) {
        this.roleInfoRepository = roleInfoRepository;
    }

    public List<RoleInfo> findAll(FindAllRoleInfoDto param) {
        Specification<RoleInfo> specification = WhereMakerUtils.<RoleInfo>is("creatorId", param.getCreatorId())
                .and(
                        WhereMakerUtils.<RoleInfo>like("roleName", param.getRoleName())
                                .or(WhereMakerUtils.range("createDate", param.getCreateDateBegin(), param.getCreateDateEnd()))
                )
                ;
        return roleInfoRepository.findAll(specification);
    }
}
